package web.utils;

import com.alibaba.fastjson.JSONObject;

public class R {
    private Integer code;
    private String msg;
    private Object data;
    public static R ok(){
        R r=new R();
        r.code=200;
        r.msg="请求成功";
        return r;
    }

    public static R ok(String msg){
        R r=new R();
        r.code=200;
        r.msg=msg;
        return r;
    }
    public static R error(){
        R r=new R();
        r.code=500;
        r.msg="请求失败";
        return r;
    }
    public static R error(String msg){
        R r=new R();
        r.code=500;
        r.msg=msg;
        return r;
    }

    public R setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public R setCode(Integer code) {
        this.code = code;
        return this;
    }
    public R setData(Object data) {
        this.data = data;
        return this;
    }

    public Integer getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    public Object getData() {
        return data;
    }
    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }
}
